<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Adminlog Controller
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class Getphone_model extends MY_Model{
	
	public function __construct(){
		parent::__construct();
		$this->table_name = 'book_contacts';
	}
        
        public function existsbooking($params){
                $this->db->select('ct.name AS hoten, ct.customerID,ct.phone');
		$this->db->from($this->table_name . ' AS ct');
                $this->db->join('book_list_booking AS bk','bk.customerID = ct.customerID','right');
		$this->db->like('ct.phone',$params);
                $query = $this->db->get();
		return $query->result();
        }
        
        public function existsphone($params){
                $this->db->select('customerID');
		$this->db->from($this->table_name);
                $this->db->like('phone',$params);
                $query = $this->db->get();
		return $query->result();
        }
        
        public function selectAll($params){
                $this->db->select('ct.name AS hoten, ct.customerID,ct.phone, usr.username');
		$this->db->from($this->table_name . ' AS ct');
                $this->db->join('users AS usr','usr.id = ct.owner');
		$this->db->like('ct.phone',$params);
                $query = $this->db->get();
		return $query->result();
        }
        
        public function getphone(){
            $sql = "SELECT t1.phone FROM book_sales_phone AS t1 WHERE t1.status = 0 AND t1.phone NOT IN (SELECT phone FROM book_sales) ORDER BY t1.id DESC LIMIT 1";
            $query  = $this->db->query($sql);
            return $query->result();            
        }
        
        public function searchIdByPhone($params,$params1){
                $this->db->select('sl.customerID');
		$this->db->from('book_sales AS sl');
                $this->db->where('sl.owner',$params1);
		$this->db->like('sl.phone',$params);
                $query = $this->db->get();
		return $query->result();
        }
        
}